<?php

include_once('weibo/Weibo4Php.php');
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include( 'common/meta.php' );
include( 'common/header.php' );
?>
<script type="text/javascript" src="resource/js/WeiboUtility.js" ></script>
<title>话题线|北京时间</title>
</head>

<body>
	<div id="body">
	<?php
		include( 'common/account.php' );
        $adtype='ourdiary';
		include( 'common/ad.php' );
		?>

		<div class="filter-wrap"></div>
		
		<!--start <decorator:body />-->
	<script type="text/javascript">
	function followTrend(trend){
		document.getElementsByName("trend")[0].value=trend;
		document.getElementById("followTrendForm").submit();
	}
	
	function doInvent(status) {
		var form_data = {
					status:status
					}
					$.ajax({
						url: "invent.php",   //++example++  url:"sendit.php"
						type: 'POST',
						async : false,
						data: form_data, 
						dataType: "json",
       					success: function(result) {       					
							if(isEmpty(result)){
								message_box('邀请已发出');       						                          	
							}else{
								message_box(result);
							}
						}
					});
	}

	function invent(id){
		$('.invent_overlay_content').fadeOut();
		if(isEmpty(document.getElementById(id).value)){
			return;
		}
		
		var status=document.getElementById(id).value;
		doInvent(status);		
	}
	function invent2(id){
		if(isEmpty(document.getElementById(id).innerText)){
			return;
		}
		
		var status=document.getElementById(id).innerText;
		doInvent(status);
	}

	function insert_trend(id){
		var data = $('#item'+id).val();
		$('.invent_content').append(data);
		
	}

	function invent_trend(friend_name,sIndex,trend_list){
			$('.invent_overlay').fadeIn();
			$('.invent_overlay_content').fadeIn();
			var myTrendlist = trend_list.split('#');
			
			jQuery.each(myTrendlist,function(index,item){
				if(item !==''){
					$('.invent_trendbox').append("<input type='button' id='item"+index+"' value='#"+item+"#' onclick='insert_trend("+index+");' />");
					}
				});
			var $invent_content_data ='<br/><textarea rows="10" cols="50" class="invent_content" id="trends'+sIndex+'">'+'@'+'<?=$_SESSION['user']->screen_name?>&nbsp;'+'通过话题线邀请@'+friend_name+'</textarea>';
			$('.invent_contentbox').html($invent_content_data);
			
			var $invent_sumbit_data = '<input type="button" value="邀请" onclick="invent('+"'trends"+sIndex+"'"+')" />';
			$('.invent_submit').html($invent_sumbit_data);
				   
	}

	function invent_morefriend(trend){
		//TODO
          /*
			ourdiaryDwr.getFriends(trend,function (result){
				var html="";
				if(result==null||result.length==0){
					html+="<a href=\"http://weibo.com/f/find\" target=\"blank\">加几个朋友吧</a>";
				} else {
					foreach(var i=0; i<result.length;i++){
						html+="<li><img src=\""+result[i]->avatar_large+"\" width=\"110px\"/><br/>"+result[i]->screen_name+"<div class=\"clear\"></div></li>";
					}
				}			
				$(".col_friend_list2").html(html);
				
				var trend_key = "#"+trend+"#";
				$('.invent_overlay2').fadeIn();
				$('.invent_overlay_content').fadeIn();
				var $container_weibo = $('.invent_overlay_trend');
				$container_weibo.imagesLoaded( function(){
						$container_weibo.masonry({
							itemSelector : '.box',
						columnWidth: 5,
						isAnimated: true});
				});
				$('.invent_trend_name').append(trend_key);
				$('.invent_text span').append(trend_key);
			});
	*/		
	}

	function message_box(msg){ 
			$('.invent_trendbox').html('');
			
			$('.message_box').html(msg);
			$('.message_box').fadeIn().delay(2000).fadeOut(function(){
				$('.invent_overlay').fadeOut();
			});

	}

	</script>
//TODO
	<form action="./ourdiary.html?method.followTrend=" method="post" id="followTrendForm">
	<input type="hidden" name="trend" />
	</form>
	<div class="invent_overlay">
	<div class="invent_overlay_bg"></div>
	<div class="invent_overlay_content">
	<span class="invent_trendbox"></span>
	 <span class="invent_contentbox"></span>
	 <br/>
	<span class="invent_submit"></span>
	</div>

	</div>
	<div class="invent_overlay2">
	<div class="invent_overlay_bg"></div>
	<div class="invent_overlay_trend" class="content_friends clearfix">
	<ul class="box col_friend_list2">
	</ul>
	</div>
	</div>
	<div id="container_weibo">

		<ul id="friends_trend" class="friends_trend" >
			<li class="active"><a href="#friend_trend">朋友关注的话题</a></li>
			<li><a href="#box_trend">话题集</a></li>
			<li><a href="javascript:void(0)" onclick="location.href='./line.php';">话题线</a></li>
			<li><a href="javascript:void(0)" onclick="location.href='./refresh.php?redirect=trendsAndFriends';">刷新</a></li>			
		</ul>
		<div id="friend_trend" class="content_friendstrend clearfix"  >
			<?php
			$weibo4php = $_SESSION['weibo4php'];	
			$trends=$weibo4php->trends;
			
			
			//var_dump($weibo4php);
			echo "==========";
			//var_dump($trends);
			$alltrends="";
			foreach($trends as $trend) {
				echo $alltrends = "#".$trend['hotword'];
			}

			$allFriendTrends = $weibo4php->getAllFriendTrends();
			if(empty($allFriendTrends)){
				echo "<a href=\"http://weibo.com/f/find\" target=\"blank\">加几个朋友吧</a>";
			} else {
					$friends = $weibo4php->friends;
					var_dump($friends);
					for($index=0;$index<count($friends);$index++){
					$ft_item = $friends[$index];		
						
				
					//$hisTrends = $weibo4php->getTrends($ft_item['id'],1);?>
					<ul class="box col_friend_list">
					<li><img src="<?=$ft_item['avatar_large']?>" width="100" /><br/><?=$ft_item['screen_name']?>
					<ul>
					<?php //foreach($hisTrends as $trend_item):?>
					<li><?//$trend_item['hotword']?></li>
					<?php //endforeach;?>
					</ul>
					<div class="clear"></div>
					</li>
					</ul>
					
					
				
				<?php }/*foreach (array_keys($allFriendTrends) as $key) {
					
					$firend = $weibo4php->friends[$key];
					if ($firend->avatar_large){echo $firend->avatar_large;}else{echo 'fuck!';}
					echo "<ul class=\"box col_friend_list\">";
					echo "<li>";
					echo '<img src=\"'.$firend->avatar_large.'" width=\"110px\"/><br/>'.$firend->screen_name;
					echo "<ul>";
					$unfollow = $alltrends;
					$trends = $allFriendTrends[$key];
					foreach($trends as $item2 ){
						echo "<li><a href=\"./line.php?trend=\" onclick=\"encodeZH(this)\">".$item2->hotword." /></a>&nbsp; ";
						if(stripos($alltrends, $item2->hotword)){
							echo "已关注";
							$unfollow = str_ireplace($item2->hotword,"",$unfollow);
						} else {
							echo "<span onclick=\"followTrend('".$item2->hotword."')\">+关注</span>";
						}
						echo "</li>";
					}
					echo "</ul>";		
					echo "<div class=\"clear\"></div>";
					echo "</li>";
					echo "<div class=\"friend_trendbox_btns\">";
					//'".$firend->screen_name."','".$index."','".$unfollow"'
					echo "<a href=\"javascript:void(0)\" onclick=\"invent_trend('".$firend->screen_name."','".$index."')\">话题邀请</a>";
					echo "</div>";
					echo "</ul>";
					$index++;
				}*/?>
			<?php }
			?>				
		</div>
		<div id="box_trend" class="content_friendstrend">
			<div class="trends_array">
			<?php			
				/*foreach(array_keys($weibo4php->trendPaticipators) as $key) {
					echo "<div class=\"trends\">";
					echo "<span><a href=\"./line.php?trend=\" onclick=\"encodeZH(this)\">".$key."</a>&nbsp; &nbsp;";
					if(stripos($alltrends, $key)){
						echo "已关注 <a href=\"javascript:void(0)\" onclick=\"invent_morefriend('".$key."');\">邀请更多好友</a>";
					} else {
						echo "<a href=\"javascript:followTrend('".$key."')\">加关注</a>";
					}
					echo "</span><br/><br/>";
					$firends = $weibo4php->trendPaticipators[$key];
					foreach($firends as $item2 ){
						echo "<li><img src=\"".$item2->avatar_large."\" width=\"110\"/><br/>".$item2->screen_name."</li>";
					}
					echo "<div class=\"clear\"></div>";
					echo "</div>";
				}*/
			?>
			</div>
		</div>
		<div class="clear"></div>
	</div>
	<div class="message_box"></div>

		<!--end <decorator:body />-->
	</div>

		<?php
		include( 'common/footer.php' );
		?>
                
</body>

</html>